import cv2 as cv
import os

save_path = './cal_images'
if not os.path.exists(save_path):
    print('文件夹不存在{0}，创建了此文件夹'.format(save_path))
    os.makedirs(save_path)

cap = cv.VideoCapture(0)

count = 0
while cap.isOpened():

    ret, frame = cap.read()

    cv.imshow('frame', frame)

    key = cv.waitKey(1)
    
    if key == ord('s'): 
        res = cv.imwrite("{0}/img{1}.png".format(save_path, count), frame)
        if res:
         print('board图片已经成功生成，位于' + "{0}/img{1}.png".format(save_path, count))
        else:
            print('未能成功生成!')
        count += 1

    elif key == 27:
        break